package com.shardingsphere.example.sharding;

/**
 * 取模哈希分表策略
 */
public class ModHashShardingStrategy implements ShardingStrategy {

    @Override
    public String getTableSuffix(Object shardingValue, int tableCount) {
        if (shardingValue == null) {
            return "0";
        }
        String value = shardingValue.toString();
        int hash = Math.abs(value.hashCode());
        return String.valueOf(hash % tableCount);
    }
}
